using System.Configuration;
using System.IO;
using System.Collections.Generic;
namespace mock_ehr_lib.Data.LookupServices
{
    public class SNOMEDLookupService : ILookupService
    {
        private static SNOMEDLookupService _instance;
        private readonly Dictionary<string, string> _lookup;

        public static SNOMEDLookupService Instance
        {
            get
            {
                return _instance ?? (_instance = new SNOMEDLookupService());
            }
        }
        private SNOMEDLookupService()
        {
            _lookup = new Dictionary<string, string>();
            var filename = ConfigurationManager.AppSettings["snomedFilename"];
            var lines = File.ReadAllLines(filename);
            foreach (var line in lines)
            {
                var fields = line.Split('\t');
                var code = fields[0];
                var desc = fields[2];
                _lookup.Add(code, desc);
            }
        }

        public string GetDescriptionByCode(string code)
        {
            return _lookup[code];
        }
    }
}